<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>脱敏结果 - 数据脱敏工具</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <style>
        body {
            padding-top: 2rem;
            padding-bottom: 2rem;
        }
        .result-section {
            margin-bottom: 2rem;
            padding: 1.5rem;
            border-radius: 0.5rem;
            background-color: #f8f9fa;
        }
        .entity-badge {
            display: inline-block;
            margin: 0.2rem;
            padding: 0.3rem 0.6rem;
            border-radius: 0.25rem;
            font-size: 0.875rem;
            font-weight: 600;
        }
        .entity-PER { background-color: #ffcccb; }
        .entity-ORG { background-color: #c2f0c2; }
        .entity-LOC, .entity-GPE { background-color: #c2e0ff; }
        .entity-PHONE { background-color: #ffffcc; }
        .entity-ID { background-color: #e6ccff; }
        .entity-BANK { background-color: #ffd8b1; }
        .entity-EMAIL { background-color: #d9d9d9; }
        .entity-IP { background-color: #b1e8ff; }
        .entity-DATE, .entity-TIME { background-color: #c2f0f0; }
        .entity-MONEY { background-color: #ffc2e0; }
        .entity-DEFAULT { background-color: #e6e6e6; }
        pre {
            white-space: pre-wrap;
            word-wrap: break-word;
            background-color: #f5f5f5;
            padding: 1rem;
            border-radius: 0.5rem;
            max-height: 500px;
            overflow-y: auto;
        }
    </style>
</head>
<body>
    <div class="container">
        <header class="mb-5 text-center">
            <h1>法律文档脱敏结果</h1>
            <p class="lead">文档已成功脱敏，可以安全地用于云端LLM服务</p>
        </header>

        {% with messages = get_flashed_messages() %}
            {% if messages %}
                <div class="alert alert-info">
                    <ul class="mb-0">
                        {% for message in messages %}
                            <li>{{ message }}</li>
                        {% endfor %}
                    </ul>
                </div>
            {% endif %}
        {% endwith %}

        <div class="row mb-4">
            <div class="col-md-12">
                <div class="d-flex justify-content-between align-items-center">
                    <h2>脱敏文档: {{ filename }}</h2>
                    <div>
                        <a href="{{ url_for('download_file', filename=filename) }}" class="btn btn-primary me-2">
                            <i class="bi bi-download"></i> 下载脱敏文档
                        </a>
                        <form action="{{ url_for('unmask_file', filename=filename) }}" method="post" class="d-inline">
                            <button type="submit" class="btn btn-secondary">
                                <i class="bi bi-arrow-counterclockwise"></i> 恢复原始文档
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-8">
                <div class="result-section">
                    <h3>脱敏后的文档内容</h3>
                    <pre>{{ masked_content }}</pre>
                </div>
            </div>
            <div class="col-md-4">
                <div class="result-section">
                    <h3>脱敏实体信息</h3>
                    <div class="entity-list">
                        {% if masked_entities %}
                            <table class="table table-striped table-hover">
                                <thead>
                                    <tr>
                                        <th>脱敏标识</th>
                                        <th>实体类型</th>
                                        <th>原始值</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for masked_id, (original_text, entity_type) in masked_entities.items() %}
                                        <tr>
                                            <td><code>{{ masked_id }}</code></td>
                                            <td><span class="entity-badge entity-{{ entity_type }}">{{ entity_type }}</span></td>
                                            <td>{{ original_text }}</td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        {% else %}
                            <div class="alert alert-info">没有找到需要脱敏的实体</div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        <div class="row mt-4">
            <div class="col-md-12 text-center">
                <a href="{{ url_for('index') }}" class="btn btn-outline-primary">
                    <i class="bi bi-arrow-left"></i> 返回首页
                </a>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>